home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / reuse.lha / reuse / m2c / MemoryDrv.c < prev    next >
C/C++ Source or Header  |  1992-08-18  |  3KB  |  109 lines

  1. #include "SYSTEM_.h"
  2.  
  3. #ifndef DEFINITION_Memory
  4. #include "Memory.h"
  5. #endif
  6.  
  7. #ifndef DEFINITION_IO
  8. #include "IO.h"
  9. #endif
  10.  
  11. static ADDRESS p1, p2, p3, p4;
  12. static CARDINAL i;
  13. static LONGINT small, best, notbest, large;
  14. static ADDRESS AllocPrint ARGS((LONGINT n));
  15.  
  16.  
  17. static ADDRESS AllocPrint
  18. # ifdef __STDC__
  19. (LONGINT n)
  20. # else
  21. (n)
  22. LONGINT n;
  23. # endif
  24. {
  25.   ADDRESS a;
  26.  
  27.   a = Memory_Alloc(n);
  28.   IO_WriteS((System_tFile)IO_StdOutput, (STRING)"Alloc:  n = ", 12L);
  29.   IO_WriteLong((System_tFile)IO_StdOutput, n, 10L);
  30.   IO_WriteS((System_tFile)IO_StdOutput, (STRING)", ADR = ", 8L);
  31.   IO_WriteN((System_tFile)IO_StdOutput, (LONGCARD)(INTEGER)a, 8L, 16L);
  32.   IO_WriteNl((System_tFile)IO_StdOutput);
  33.   return a;
  34. }
  35.  
  36. void BEGIN_MODULE()
  37. {
  38.   BEGIN_Memory();
  39.   BEGIN_IO();
  40.  
  41.   for (i = 0; i <= 62; i += 1) {
  42.     p1 = AllocPrint((LONGINT)i);
  43.     p2 = AllocPrint((LONGINT)i);
  44.     Memory_Free((LONGINT)i, p1);
  45.     Memory_Free((LONGINT)i, p2);
  46.     p3 = AllocPrint((LONGINT)i);
  47.     p4 = AllocPrint((LONGINT)i);
  48.     if (p3 != p2) {
  49.       IO_WriteS((System_tFile)IO_StdOutput, (STRING)"Alloc/Free small not inverse ", 29L);
  50.       IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)i, 10L);
  51.       IO_WriteNl((System_tFile)IO_StdOutput);
  52.     }
  53.     if (p4 != p1) {
  54.       IO_WriteS((System_tFile)IO_StdOutput, (STRING)"Alloc/Free small not inverse ", 29L);
  55.       IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)i, 10L);
  56.       IO_WriteNl((System_tFile)IO_StdOutput);
  57.     }
  58.   }
  59.   small = 80;
  60.   best = 96;
  61.   notbest = 112;
  62.   large = 128;
  63.   for (;;) {
  64.     for (i = 7; i <= 24; i += 1) {
  65.       IO_WriteS((System_tFile)IO_StdOutput, (STRING)"        i = ", 12L);
  66.       IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)i, 10L);
  67.       IO_WriteNl((System_tFile)IO_StdOutput);
  68.       p1 = AllocPrint(small);
  69.       p2 = AllocPrint(best);
  70.       p3 = AllocPrint(notbest);
  71.       p4 = AllocPrint(large);
  72.       if (p1 == NIL || p2 == NIL || p3 == NIL || p4 == NIL) {
  73.         goto EXIT_1;
  74.       }
  75.       Memory_Free(large, p4);
  76.       Memory_Free(notbest, p3);
  77.       Memory_Free(best, p2);
  78.       Memory_Free(small, p1);
  79.       p1 = AllocPrint(best);
  80.       if (p1 != p2) {
  81.         IO_WriteS((System_tFile)IO_StdOutput, (STRING)"Alloc/Free large not inverse ", 29L);
  82.         IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)i, 10L);
  83.         IO_WriteNl((System_tFile)IO_StdOutput);
  84.       }
  85.       p1 = AllocPrint(best);
  86.       if (p1 != p3) {
  87.         IO_WriteS((System_tFile)IO_StdOutput, (STRING)"Alloc/Free large not inverse ", 29L);
  88.         IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)i, 10L);
  89.         IO_WriteNl((System_tFile)IO_StdOutput);
  90.       }
  91.       p1 = AllocPrint(best);
  92.       if (p1 != p4) {
  93.         IO_WriteS((System_tFile)IO_StdOutput, (STRING)"Alloc/Free large not inverse ", 29L);
  94.         IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)i, 10L);
  95.         IO_WriteNl((System_tFile)IO_StdOutput);
  96.       }
  97.       INC1(small, small);
  98.       INC1(best, best);
  99.       INC1(notbest, notbest);
  100.       INC1(large, large);
  101.     }
  102.   } EXIT_1:;
  103.   IO_WriteNl((System_tFile)IO_StdOutput);
  104.   IO_WriteS((System_tFile)IO_StdOutput, (STRING)"Memory used: ", 13L);
  105.   IO_WriteI((System_tFile)IO_StdOutput, (LONGINT)Memory_MemoryUsed, 10L);
  106.   IO_WriteNl((System_tFile)IO_StdOutput);
  107.   IO_CloseIO();
  108. }
  109.